package org.example.wx_springboot.controller;


import lombok.extern.slf4j.Slf4j;
import org.example.wx_springboot.common.Result;
import org.example.wx_springboot.entity.Commodity;
import org.example.wx_springboot.entity.GoodsLists;
import org.example.wx_springboot.entity.Shoppingcart;
import org.example.wx_springboot.service.ICommodityService;
import org.example.wx_springboot.service.IGoodsListsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin//这个注解是解决跨域错误的
@RestController
@Slf4j
@RequestMapping("/goodsLists")
public class GoodsListsController {
    @Autowired
    IGoodsListsService goodsListsService;


    @GetMapping("/list")
    public Result list(){
        List<GoodsLists> goodsLists = goodsListsService.list();
        return Result.success(goodsLists);//返回CommodityMapper的数据
    }

    @PostMapping("/seve")
    public Result save(@RequestBody GoodsLists goodsLists){
        goodsListsService.save(goodsLists);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        goodsListsService.deleteById(id);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody GoodsLists obj){
        goodsListsService.update(obj);
        return Result.success();
    }

}
